//
//  TKIMAccountHeadView.m
//  test2
//
//  Created by TryHone on 17/5/19.
//  Copyright © 2017年 TryHone. All rights reserved.
//

#import "TKIMAccountHeadView.h"
@interface TKIMAccountHeadView()
@property(nonatomic,strong) UIImageView* bgImage;//背景图片
@end

@implementation TKIMAccountHeadView
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self){
        [self buildUI];
       
    }
    return self;
}

-(void)buildUI{
    [self addSubview:self.bgImage];
    [self.bgImage addSubview:self.face];
    [self.bgImage addSubview:self.username];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self);
    }];
    [self.face mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bgImage.mas_centerY).offset(-25);
        make.centerX.mas_equalTo(self.bgImage.mas_centerX);
        make.width.mas_equalTo(@50);
        make.height.mas_equalTo(@50);
    }];
    [self.username mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.face.mas_bottom).offset(10);
        make.left.mas_equalTo(self.bgImage.mas_left);
        make.right.mas_equalTo(self.bgImage.mas_right);
    }];
}

-(UIImageView *)face{
   
    if (!_face) {
        _face = [[UIImageView alloc] init];
        _face.layer.masksToBounds = YES;
        _face.layer.cornerRadius = 25;
//        _face.image =TKIMGetImage(@"im_icon_userDefault"); //[UIImage imageNamed:@"im_icon_userDefault"];
        _face.userInteractionEnabled = YES;
        UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
        singleTap.numberOfTapsRequired = 1; // 单击
        [_face addGestureRecognizer:singleTap];
    }
    return _face;
}
-(UILabel*)username{

    if (!_username) {
        _username = [[UILabel alloc] init];
        _username.backgroundColor = [UIColor clearColor];
        _username.textAlignment = NSTextAlignmentCenter;
        _username.text = @"AlanWang";
        
    }
    return _username;
}

-(UIImageView*)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc] init];
        _bgImage.image = [UIImage imageNamed:@"im_bg_contact_male"];
        _bgImage.userInteractionEnabled = YES;
    }
    return _bgImage;
}
/**
 *  @author Alan, 17-06-01 16:06:25
 *
 *  @brief <#Description#>
 *
 *  @param tap <#tap description#>
 */
-(void)singleTap:(UITapGestureRecognizer*)tap{
    [self routerEventWithName:TKIMCHANGEFACE userInfo:nil];
}

@end
